package com.xm.xmapp;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.xm.xmapp.app.Constants;
import com.xm.xmapp.app.MyAppcation;
import com.xm.xmapp.base.BaseActivity;
import com.xm.xmapp.customview.CustomLayout;
import com.xm.xmapp.customview.TipDialog;
import com.xm.xmapp.myinterface.DisssmissInterFace;
import com.xm.xmapp.myinterface.GetDataInterFace;
import com.xm.xmapp.myinterface.MyDialogButton;
import com.xm.xmapp.request.bean.LogoutRequest;
import com.xm.xmapp.tools.Tools;

public class SettingActivity extends BaseActivity implements OnClickListener {

	private CustomLayout guanyu, falv, jianyi, pinjia, denglu, find,wenti;
	private TextView tuichu;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_setting);
	}

	@Override
	public void initView() {

		tuichu = (TextView) findViewById(R.id.tuichu);
		guanyu = (CustomLayout) findViewById(R.id.guanyu);
		falv = (CustomLayout) findViewById(R.id.falv);
		jianyi = (CustomLayout) findViewById(R.id.jianyi);
		pinjia = (CustomLayout) findViewById(R.id.pinjia);
		denglu = (CustomLayout) findViewById(R.id.denglu);
		wenti = (CustomLayout) findViewById(R.id.wenti);
		find = (CustomLayout) findViewById(R.id.find);
	}

	@Override
	public void initData() {
		setMyTitle("设置");
	
	}

	@Override
	public void initEvent() {
		
		guanyu.setOnClickListener(this);
		falv.setOnClickListener(this);
		jianyi.setOnClickListener(this);
		pinjia.setOnClickListener(this);
		tuichu.setOnClickListener(this);
		denglu.setOnClickListener(this);
		find.setOnClickListener(this);
		wenti.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
	
		switch (v.getId()) {
		
		case R.id.wenti:
			intent = new Intent(MyAppcation.getMyAppcation(),
					QuestionListActivity.class);
			startActivity(intent);
			break;
		case R.id.denglu:
			intent = new Intent(MyAppcation.getMyAppcation(),
					UpPassWordActivity.class);
			startActivity(intent);
			break;

		case R.id.find:
			intent = new Intent(MyAppcation.getMyAppcation(),
					SettingPingActivity.class);
			startActivity(intent);
			break;

		case R.id.guanyu:
			intent = new Intent(MyAppcation.getMyAppcation(),
					AboutOurSelfActivity.class);
			startActivity(intent);
			break;
		case R.id.falv:
			intent = new Intent(MyAppcation.getMyAppcation(),
					ShowURLActivity.class);
			intent.putExtra("url", Constants.User_agreement);
			intent.putExtra("title", "用户协议");
			startActivity(intent);
			break;
		case R.id.jianyi:
			intent = new Intent(MyAppcation.getMyAppcation(),
					AppFeedbackActivity.class);
			startActivity(intent);
			break;
		case R.id.pinjia:
			Tools.startPinjia();
			break;
		case R.id.tuichu:
			TipDialog tipDialog = new TipDialog(this, "温馨提示", "您确定退出登录吗?",
					new MyDialogButton() {

						@Override
						public void setTitle(int flag, String str) {
						
							logoutRequest();
						}
					});
			tipDialog.show();
			break;
		default:
			break;
		}
	}
	
	public void logoutRequest() {

		LogoutRequest requestBean = new LogoutRequest();
		promptDialog.show();
		MyAppcation.getMyAppcation().getPostData(this, requestBean,
				new GetDataInterFace<String>() {

					@Override
					public void onResponse(String response) {

						promptDialog.dismiss();
						MyAppcation.getMyAppcation().clearUserBean();	
						intent = new Intent(MyAppcation.getMyAppcation(),
								MainActivity.class);
						intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
						startActivity(intent);

					}
				}, new DisssmissInterFace() {

					@Override
					public void putError(VolleyError error) {

						promptDialog.dismiss();
					}
				});

	}
}
